﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CongThongTin.Entities;
using System.Text;

namespace CongThongTin
{
    public partial class Client : System.Web.UI.MasterPage
    {
        CongThongTinEntities _entities = new CongThongTinEntities();

        protected void Page_Load(object sender, EventArgs e)
        {
            loadMenu();
        }

        void loadMenu()
        { 
            StringBuilder menuHTML=new StringBuilder ();

            menuHTML.Append("<ul>");
            menuHTML.Append("<li><a href='Default.aspx'>Trang chủ</a></li>");

            //loai van ban
            if(_entities.THELOAIVANBANs.Count()>0)
            {
                List<THELOAIVANBAN> lTheLoaiVanBan=_entities.THELOAIVANBANs.ToList();

                menuHTML.Append("<li><a href='#'>Văn bản mới</a>");
                menuHTML.Append("<ul>");
                foreach(THELOAIVANBAN tl in lTheLoaiVanBan)
                {
                    menuHTML.Append("<li><a href='MyInfo.aspx?option=1&tl=" + tl.MATHELOAI + "'>" + tl.TENTHELOAI + "</a></li>");
                }
                menuHTML.Append("</ul>");
                menuHTML.Append("</li>");
            }
            else{
                   menuHTML.Append("<li><a href='#'>Văn bản mới</a>");
            }
            //loai tin tuc 
            List<THELOAI> lTheloai=_entities.THELOAIs.ToList();

            foreach (THELOAI tl in lTheloai)
            {
                List<LOAITIN> lLoaitin = _entities.LOAITINs.Where(lt=>lt.MATHELOAI== tl.MATHELOAI).ToList();

                if (lLoaitin.Count > 1)
                {
                    menuHTML.Append("<li><a href='#'>" + tl.TENTHELOAI + "</a>");
                    menuHTML.Append("<ul>");
                    foreach (LOAITIN lt in lLoaitin)
                    {
                        menuHTML.Append("<li><a href='MyInfo.aspx?option=1&tl=" + lt.MALOAITIN + "'>" + lt.TENLOAITIN + "</a></li>");
                    }
                    menuHTML.Append("</ul>");
                    menuHTML.Append("</li>");
                }
                else
                {
                    LOAITIN oLoaiTin = _entities.LOAITINs.FirstOrDefault(lt => lt.MATHELOAI == tl.MATHELOAI);
                    if(oLoaiTin!=null)
                        menuHTML.Append("<li><a href='MyInfo.aspx?option=1&tl=" + oLoaiTin.MALOAITIN + "'>" + tl.TENTHELOAI + "</a></li>");
                }
            }

            //hinh anh
           
            menuHTML.Append("<li><a href='HinhAnh.aspx'>Hình ảnh</a>");
            menuHTML.Append("<li><a href='LienHe.aspx'>Liên hệ</a>");

            menuHTML.Append("</ul>");

            ltrmenu.Text = menuHTML.ToString();
          
        }
    }
}